package com.xxkj.orcfx.web;


import java.io.Serializable;
import java.util.Map;

public class Resp<T> implements Serializable {
    private static final long serialVersionUID = 1L;


    /**
     * 返回状态码
     */
   // @ApiModelProperty(value = "返回状态码:00:成功，99：失败")
    private String code;

    /**
     * 返回消息
     */
    //@ApiModelProperty(value = "返回消息")
    private String msg;

    /**
     * 返回内容
     */
    //@ApiModelProperty(value = "返回实体内容")
    private T result;

    /**
     * 其他内容
     */
    private Map<String, Object> ext;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }


    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getExt() {
        return ext;
    }

    public void setExt(Map<String, Object> ext) {
        this.ext = ext;
    }

    public Resp(){
    	this.code = RespCode.SUCCESS.getCode();
    	this.msg = RespCode.SUCCESS.getCode();
    }

    public Resp(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Resp(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.setResult(data);
    }

    public Resp(String code, String msg, T data, Map<String, Object> ext) {
        this.code = code;
        this.msg = msg;
        this.setResult(data);
        this.ext = ext;
    }

    //快速返回成功
    public static <T>Resp success(){
        return new Resp<T>(RespCode.SUCCESS.getCode(),"成功",null);
    }

    public static <T>Resp success(T result){
        return new Resp<T>(RespCode.SUCCESS.getCode(),"成功",result);
    }

    public static <T>Resp success(T result, Map<String, Object> extra){
        return new Resp<T>(RespCode.SUCCESS.getCode(),"成功",result, extra);
    }

    public static <T>Resp success(String msg, T result){
        return new Resp<T>(RespCode.SUCCESS.getCode(),msg,result);
    }

    public static <T>Resp success(String msg, T result, Map<String, Object> extra){
        return new Resp<T>(RespCode.SUCCESS.getCode(),msg,result, extra);
    }


    //快速返回失败状态
    public static <T>Resp fail(){
        return new Resp<T>(RespCode.FAIL.getCode(),RespCode.FAIL.getDesc());
    }

    public static <T>Resp fail(String msg){
        return new Resp<T>(RespCode.FAIL.getCode(),msg);
    }

    public static <T>Resp fail(String msg, T result){
        return new Resp<T>(RespCode.FAIL.getCode(),msg,result);
    }

    public static <T>Resp fail(String code, String msg){
        return new Resp<T>(code,msg,null);
    }

    public static <T>Resp fail(String msg, T result, Map<String, Object> extra){
        return new Resp<T>(RespCode.FAIL.getCode(),msg,result, extra);
    }



    //快速返回自定义状态码
    public static <T>Resp result(String code, String msg){
        return new Resp<T>(code,msg);
    }

    public static <T>Resp result(String code, String msg, T result){
        return new Resp<T>(code,msg,result);
    }

    public static <T>Resp result(String code, String msg, T result, Map<String, Object> extra){
        return new Resp<T>(code,msg,result, extra);
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }
}
